<?php
	include('./includes/db_connect.php');
	$id = $_GET["id"];
	if($id) {
		$query = "select * from user where id = ".$id;
		$row = mysql_fetch_array(mysql_query($query));
		$userName = $row['user_name'];
		$location_id = $row['location_id'];
		$status = $row["status"];
		$title = "Edit User: ".$userName;
	} else {
		$title = "Create User";
		$id = 0;
	}
	
	
?>
<h3><?php echo $title ?></h3>
<form action="./actions/ProcessUserEdit.php" method="post">
<?php if($_GET["Error"]) {?><p class="alert2"><?php echo $_GET["Error"]; ?></p><?php }?>
<div style="background:#eee; border:1px #ddd solid;padding:10px;">
<table width="100%">
  <tr>
    <td valign="top">
      <div class="formUnitVertical">
        <label>User Name:</label><br/>
        <input type="text" name="name" value="<?php echo $userName ?>"/>
      </div>
    </td>
    <td valign="top">
      <div class="formUnitVertical">
        <label>Location:</label><br/>
        <select name="location">
          <?php 
            $locationQuery = "select * from lst_location";
            $result = mysql_query($locationQuery);
            while($row=mysql_fetch_array($result)) {
              $loc_id = $row["id"];
              $location = $row["location"];
              if($location_id==$loc_id)
                echo "<option value=\"".$loc_id."\" selected>".$location."</option>";
              else
                echo "<option value=\"".$loc_id."\">".$location."</option>";
            }
          ?>
          </select>
      </div>
    </td>
    <td valign="middle">
      <input type="checkbox" <?php if($status==1) echo "checked "?> name="status" />
      <label>Enabled?</label>
    </td>
  </tr>
  <tr>
  	<td colspan="3" style="padding-top:20px;font-weight:bold;">Change Password</td>
  </tr>
   <tr>
    <td valign="top">
      <div class="formUnitVertical">
        <label>Password:</label><br/>
        <input type="password" name="pass1"/>
      </div>
    </td>
    <td>
    	<div class="formUnitVertical">
        <label>Re-enter Password:</label><br/>
        <input type="password" name="pass2"/>
      </div>
    </td>
    <td/>
  </tr>
  <tr>
  	<td colspan="3" style="padding-top:20px"></td>
  </tr>
  <tr>
    <td colspan="3" align="right" style="border-top:1px #ccc solid">
    	<input type="hidden" value="<?php echo $id;?>" name="id" />
      <input type="submit" class="btn" value="Save"/>
      <input class="btn" type="button" value="Cancel" 
          onclick="window.location='admin.php';"/>
    </td>
  </tr>
</table>
</div>
</form>